package com.example.androidlesson;

import android.app.AlertDialog;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class InfoFragment extends Fragment implements View.OnClickListener {

    private static InfoFragment instance;
    private InfoFragment() {}
    public static InfoFragment GetInfoFragment(){
        if(instance==null){
            instance = new InfoFragment();
        }
        return instance;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_info, container, false);
        Button  button= (Button) view.findViewById(R.id.reg_button);
        if(button != null){
            button.setOnClickListener(this);
        }
        return view;
    }

    @Override
    public void onClick(View v){
        Log.d("调试信息","按钮被点击");
        showMyDialog();
    }

    // --------------------------------------------------------------------------------
    //自定义登录框
    private AlertDialog alert = null;
    private AlertDialog.Builder builder = null;


    //视图自定义
    private View view_custom;
    public void showMyDialog()
    {
        //初始化Builder
        builder = new AlertDialog.Builder(this.getActivity());

        //加载自定义的那个View,同时设置下
        final LayoutInflater inflater = this.getActivity().getLayoutInflater();
        view_custom = inflater.inflate(R.layout.dialog_regedit, null,false);
        builder.setView(view_custom);
        builder.setCancelable(false);
        alert = builder.create();

        view_custom.findViewById(R.id.btn_cancle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity().getApplicationContext(), "对话框已关闭~", Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });

        view_custom.findViewById(R.id.btn_reg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity().getApplicationContext(), "注册按钮", Toast.LENGTH_SHORT).show();

                alert.dismiss();
            }
        });

        view_custom.findViewById(R.id.btn_check).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity().getApplicationContext(), "验证码按钮~", Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

}